<template>
	<div class="nav">
		<el-page-header @back="goBack"  content="去登录">
		</el-page-header>
		<br />
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="用户名:">
				<el-input v-model="form.name"></el-input>
			</el-form-item>
			<el-form-item label="密码:">
				<el-input v-model="form.pwd"></el-input>
			</el-form-item>
			<el-form-item label="手机号:">
				<el-input v-model="form.phone"></el-input>
			</el-form-item>
			<el-form-item label="性别">
				<el-select v-model="form.gender" placeholder="请选择您的性别:">
					<el-option label="男" value="男"></el-option>
					<el-option label="女" value="女"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="出生年月">
				<el-col :span="11">
					<el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;">
					</el-date-picker>
				</el-col>
				<el-col class="line" :span="2">-</el-col>
				<el-col :span="11">
					<el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker>
				</el-col>
			</el-form-item>
			<el-form-item label="身份">
				<el-select v-model="form.region" placeholder="请选择身份:">
					<el-option label="管理员" value="admin"></el-option>
					<el-option label="老师" value="teacher"></el-option>
					<el-option label="学生" value="student"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="是否在籍">
				<el-switch v-model="form.delivery"></el-switch>
			</el-form-item>

			<el-form-item label="请输入补充说明">
				<el-input type="textarea" v-model.lazy="form.desc"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="onSubmit">立即注册</el-button>
				<el-button>取消</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	//引入axios
	import axios from 'axios'

	export default {
		name: 'Register',
		data() {
			return {
				form: {
					name: '',
					pwd: '',
					gender: '',
					region: '',
					date1: '',
					date2: '',
					delivery: false,
					desc: ''
				}
			}
		},
		methods: {
			onSubmit() {
				//发起ajax请求
				axios({
					//请求地址
					url: 'http://localhost:8080/axios/register.do',
					//携带参数
					params:this.form,
					/* data:{
						name:this.name
					}, */
					//请求方式
					method: 'post',
				}).then(
					res => {
						//注册成功
						alert(res.data.msg)
						if(res.data.msg){
							this.$router.push({
								path: '/login',
							})
						}
					},
					err => {
						console.log(err.message)
					}
				)

			},
			goBack() {
				this.$router.push({
					path:'/login'
				})
			}
		}
	}
</script>

<style scoped>
	.nav {
		width: 60%;
		margin: 0 auto
	}
</style>
